//
//  OAHomeEmailViewController.m
//  OASystem
//
//  Created by zhoupengfei on 16/1/17.
//  Copyright © 2016年 zpf. All rights reserved.
//

#import "OAHomeEmailViewController.h"
#import "OAInBoxViewController.h"
#import "OASendMessageViewController.h"
#import "HttpTools.h"
@interface OAHomeEmailViewController ()

@property (weak, nonatomic) IBOutlet UILabel *publicReceiveEmail;
@property (weak, nonatomic) IBOutlet UILabel *publicSendEmail;
@property (weak, nonatomic) IBOutlet UILabel *profileReceiveEmail;
@property (weak, nonatomic) IBOutlet UILabel *profileSendEmail;

@property (weak, nonatomic) IBOutlet UITableViewCell *publicReceiveCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *publicSendCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *profileReceiveCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *profileSendCell;

@property(nonatomic,assign)NSInteger whetherMail;

@property (nonatomic,strong) NSDictionary *dict;

@end

@implementation OAHomeEmailViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setLayer:self.publicReceiveEmail];
    [self setLayer:self.publicSendEmail];
    [self setLayer:self.profileReceiveEmail];
    [self setLayer:self.profileSendEmail];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
        
}

-(void)setLayer:(UILabel*)label{
    label.layer.cornerRadius = 10;
    label.layer.masksToBounds = YES;
}

-(void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchmain arrays:array method:KHomeMailwoiunu success:^(id JSON) {
        
        NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
        
        self.dict = dict;
        
        [self setSubViews:dict];
    } failure:^(NSError *error) {
        
    }];
}

-(void)setSubViews:(NSDictionary*)dict{
    
    if ([dict[@"ksmail"] integerValue] !=0) {
         self.publicReceiveEmail.text = dict[@"ksmail"];
        self.publicReceiveEmail.hidden = NO;
    }
    
    if ([dict[@"mail"] integerValue] !=0) {
        self.profileReceiveEmail.text = dict[@"mail"];
        self.profileReceiveEmail.hidden = NO;
    }
    
//科室收件箱、科室发件箱
    if ([dict[@"whetherMail"] integerValue] ==0) {
//        self.publicReceiveCell.backgroundColor = [UIColor redColor];
//        self.publicSendCell.backgroundColor = [UIColor redColor];
        self.publicReceiveCell.hidden = YES;
        self.publicSendCell.hidden = YES;
    }
    
    [self.tableView reloadData];
   
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if ([self.dict[@"whetherMail"] integerValue] == 0) {
        
        if (indexPath.row == 0 || indexPath.row == 1) {
            
            return 0;
            
        }else {
        
            return 86;
        }
    }else {
        
        return 86;
    
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
      UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    switch (indexPath.row){
        case 0:{//科室收件箱
            OAInBoxViewController * inBoxVC  = (OAInBoxViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"InBoxVCID"];
            inBoxVC.isKeShi = YES;
            [self.navigationController pushViewController:inBoxVC animated:YES];
            break;
        }
        case 1:{ //科室发件箱
            OASendMessageViewController * sendVC  = (OASendMessageViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"SendMessageVCID"];
            sendVC.isKeShi = YES;
            [self.navigationController pushViewController:sendVC animated:YES];
            break;
        }
        case 2:{ //个人收件箱
            OAInBoxViewController * inBoxVC  = (OAInBoxViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"InBoxVCID"];
            [self.navigationController pushViewController:inBoxVC animated:YES];
            break;
        }
        case 3:{ //个人发件箱
            OASendMessageViewController * sendVC  = (OASendMessageViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"SendMessageVCID"];
            [self.navigationController pushViewController:sendVC animated:YES];
            break;
        }
        default:
            break;
    }
    
}




@end
